package com.beiding.businessplatform.base;

import com.beiding.businessplatform.data.Vm;
import com.beiding.businessplatform.ql.Q;
import com.beiding.businessplatform.ql.QueryBuilder;
import com.beiding.businessplatform.ql.SelectionBuilder;

import java.util.Collections;
import java.util.List;
import java.util.Map;

public interface ServiceBase<T extends Vm> {

    List<Map<String, Object>> queryList(String ql, Map<String, Object> holderData);

    Map<String, Object> queryOne(String ql, Map<String, Object> holderData);

    default List<Map<String, Object>> queryList(String ql) {
        return queryList(ql, Collections.EMPTY_MAP);
    }

    default Map<String, Object> queryOne(String ql) {
        return queryOne(ql, Collections.EMPTY_MAP);
    }

    T create();

    T retrieve(String id);

    T findOne(String ql, Map<String, Object> holderData);

    default T findOne(String ql) {
        return (T) findOne(ql, Collections.EMPTY_MAP);
    }

    List<T> findList(String ql, Map<String, Object> holderData);

    default List<T> findList(String ql) {
        return findList(ql, Collections.EMPTY_MAP);
    }

    List<T> findList(SelectionBuilder selectionBuilder, QueryBuilder queryBuilder);

    default List<T> findList(QueryBuilder queryBuilder) {
        return findList(Q.select(), queryBuilder);
    }

    T findOne(SelectionBuilder selectionBuilder, QueryBuilder queryBuilder);

    default T findOne(QueryBuilder queryBuilder) {
        return findOne(Q.select(), queryBuilder);
    }

    void save(T a);

}
